#include <vector>
using namespace std;
/*
 * @lc app=leetcode.cn id=53 lang=cpp
 *
 * [53] 最大子数组和
 */

// @lc code=start
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int l = 0, r = 0, now = 0, res = INT_MIN;
        // 1 2 -10 3 5
        // 
        while (r < nums.size()) {
            now += nums[r];
            res = max(res, now);
            if (now < 0) {
                now = 0; 
                l = r + 1;
            }
            r++;
        }
        return res;
        
    }
};
// @lc code=end

